<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE HTML>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<base href="<%=basePath%>">
<html lang="zn-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

    <title>修改密码</title>
    <link rel="stylesheet" href="css/base.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript"src="js/base.js"></script>
    <script type="text/javascript" src="js/md5.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/handle.js"></script>
    <script type="text/javascript">
        var openId = "";
        var resetTel ="${userInfo.memberNum}"
        // 该账户的账号（电话号码）

        $(function () {
            alert_LHX({
                hasBtn: 0,
                msg: '该页面未开放'
            });
            $("#resetTel").html(resetTel);
        })
        function modifyPsw() {
            var oldpsw = $("#oldPassword").val();
            var newpsw = $("#newPassword").val();
            var newpsw2 = $("#newPassword2").val();
            var oldPsw_md,newPsw_md;
            var reg2 = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/; //仅为数字和英文字母组合

            if (oldpsw.length < 8 || oldpsw.length > 16 || newpsw.length < 8 || newpsw.length > 16) {
                errorToast("密码长度必须8到16位！", 3);
                return false;
            }
            if (!reg2.test(newpsw)) {
                errorToast("请输入密码为数字与字母的组合！", 3);
                return false;
            }
            if (oldpsw == newpsw) {
                errorToast("新密码与旧密码一致，请重新输入。", 3);
                return false;
            };
            if (newpsw != newpsw2) {
                errorToast("两次密码输入不一致，请重新输入！", 3);
                return false;
            }
            oldPsw_md = hex_md5(oldpsw) + "http://haois.me";
            newPsw_md = hex_md5(newpsw) + "http://haois.me";

            modifyPswAjax(oldPsw_md, newPsw_md)
        }
        function modifyPswAjax(oldpsw, newpsw) {
            console.log('step into modifyPswAjax()')

            $(".loading").show();
            var data = {
                oldPassword: oldpsw,
                newPassword: newpsw
            }
            $.ajax({
                url: $.httpRootPath()+'rest/user/updatePSW',
                type: 'POST',
                dataType: 'json',
                data: data,
                success: function (r) {
                    console.log(r);
                    $(".loading").hide();
                    if (r.code != "00") {
                        errorToast(r.msg, 3);
                        return false;
                    }
                    sessionStorage.setItem("tel",resetTel);
                    errorToast(r.msg+"</br>即将跳转至登录页", 3);
                    setTimeout(function(){
                        window.location.href = "wxmp/user/logout";
                    }, 3000);

                },
                error: function (e) {
                    console.log(e);
                    $(".loading").hide();
                    ajaxErrorEvent(e);
                }
            })

        }
    </script>
</head>
<body class="ed" style = "position:relative">
<div class="wrap">
    <div class="psw_context">
        <h3 class="psw_title">帐户 : <span id="resetTel"></span>

        </h3>
        <h3 class="psw_main">
            <p> <i>原密码</i>
                <input type="password" placeholder="请输入原密码" maxlength="16" id="oldPassword"></p>

            <p> <i>新密码</i>
                <input type="password" placeholder="请输入新密码" maxlength="16" id="newPassword"></p>
            <p>
                <i>确认密码</i>
                <input type="password" placeholder="请输入确认密码" maxlength="16" id="newPassword2"></p>
        </h3>

        <p class="resetBtn" onclick="modifyPsw()">确认修改</p>
    </div>
    <div class="mask_layer none"></div>
    <div class="toast toast_timeout" style="display:none">网络异常，请稍后重试！</div>
    <div class="toast toast_error" style="display:none">信息输入有误</div>
</div>

<div class="loading" style="display:none">
    <img src="img/loading.gif"></div>
</body>
</html>
